/**
 * 
 */
package edu.vanderbilt.vshare.multicast;

import java.io.IOException;
import java.io.InputStream;

/**
 * class for streaming files to the user from a multicast source
 * 
 * @author jedmondson
 *
 */
public class SRInputStream extends InputStream {

	public void listen (String ip)
	{
		SharedGlobals.threadPool_.execute(new MulticastListenerThread (ip, port));
	}

	/**
	 * blocked full read of a file
	 * 
	 * @param     filename           name of file to read
	 * @return                       contents of file
	 */

	public byte [] read (String filename)
	{		
		while (!SharedGlobals.store.isComplete(filename))
		{
			try
			{
				Thread.sleep(200);
			}
			catch (Exception e)
			{
			}
		}
		
		return SharedGlobals.store.getBytes(filename, 1);
	}
	
	/** deprecated and unused. Only included because InputStream forces
	 * us to
	 */
	@Override
	public int read() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	private int port = 10000;
}
